import axios from 'axios';

var qs = require('qs');

let basePath = '/api/v1.0/admin/';
let basePath2 = '/api/v2.0/admin/';

/**
 * 路径  start
 * ----------------------------------------------------------------------------------------------------------------------
 */

const SPECIALLINES = basePath2 + 'special_lines';

const SPECIALLINE = basePath2 + 'special_line';

const SPECIALLINESBYID = basePath2 + 'special_line_by/';

const DICTENTITY = basePath + 'fdict_entitys/fdict_entitys';

const ADDRESS_DICTS = basePath + `address_dicts`;

const ORGANIZATION_LIST = basePath + 'organizations/list';

const SPECIALLINEADDRESSS = basePath2 + 'special_line_addresss';

const SPECIALLINEADDRES_BY_USER_ID = basePath2 + 'special_line_address_by_user_id';

const SPECIALLINEADDRES_BY_ID = basePath2 + 'special_line_address_by/';

const SPECIALLINEADDRESS = basePath2 + 'special_line_address';

const SPECIALLINEADDRES_BY_USERID_AND_SPECIALLINE_ID = basePath2 + 'special_line_address_by_user_id_and_special_line_id';

const SPECIALLINEADDRES_BY_SPECIAL_LINE_ID = basePath2 + 'special_line_address_by_special_line_id/';

/**
 * 路径  end
 * ----------------------------------------------------------------------------------------------------------------------
 */

// 根据专线ID获取专线地址列表
export const getSpecialLineAddress = specialLineId => {
  return axios.get(SPECIALLINEADDRES_BY_SPECIAL_LINE_ID + specialLineId);
};

// 根据ID获取专线详情
export const getSpecialLine = id => {
  return axios.get(SPECIALLINESBYID + id.join(','));
};

// 查询字典项
export const searchDictEntitys = id => {
  return axios.get(DICTENTITY, {params: {dictCode: id}});
};

// 根据ID，获取地址列表
export const getAddresses = id => {
  let myid = `pid=` + id;
  return axios.get(ADDRESS_DICTS, {params: {filters: myid}});
};

// 获取机构列表
export const searchOrganization = params => {
  return axios.get(ORGANIZATION_LIST, {params: params});
};

// 获取专线列表
export const searchSpecialLines = params => {
  return axios.get(SPECIALLINES, {params: params});
};

// 批量启用/停用
export const batchStart = (id, isStart) => {
  return axios.post(SPECIALLINE, qs.stringify({id: id.join(','), isStart: isStart}));
};

// 批量删除
export const batchDel = id => {
  return axios.delete(SPECIALLINESBYID + id.join(','));
};

// 保存短驳
export const saveSpecialLine = (params) => {
  return axios.post(SPECIALLINES, params);
};

// 根据条件搜索获取专线列表
export const searchSpecialLine = params => {
  return axios.get(SPECIALLINE, {params: params});
};

// 保存/修改专线上地址
export const saveSpecialLineAddress = (params) => {
  return axios.post(SPECIALLINEADDRESSS, params);
};

// 根据userid获取专线地址
export const getSpeicalLineAddressByUserId = params => {
  return axios.get(SPECIALLINEADDRES_BY_USER_ID, {params: params});
};

// 根据删除专线地址
export const deleteSpecialLineAddress = id => {
  return axios.delete(SPECIALLINEADDRES_BY_ID + id);
};
// 删除专线地址根据USERID和专线ID为空
export const deleteSpecialLineAddressByUseridAndSpecialLineId = id => {
  return axios.delete(SPECIALLINEADDRESS + id);
};

// 根据userid and specalLineId查找专线地址列表
export const findByUserIdAndSpecialLineId = params => {
  return axios.get(SPECIALLINEADDRES_BY_USERID_AND_SPECIALLINE_ID, {params: params});
};
